<?php
$_create_table = "
   CREATE TABLE IF NOT EXISTS `ims_kuyuan_hb_form` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL,
        `uid` INT ( 10 ) UNSIGNED NOT NULL,
        `form_name` VARCHAR ( 10 ) NOT NULL COMMENT '表单名字',
        `form_data` text NOT NULL COMMENT '表单数据json字符串',
        `create_time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '表单创建时间',
        `status` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '状态（1=正常，9=删除）',
        PRIMARY KEY ( `id` ) 
    ) ENGINE = INNODB DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_hb_red_form` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '用户提交的红包表单数据',
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL COMMENT '公众号id',
        `uid` INT ( 10 ) UNSIGNED NOT NULL COMMENT '用户id',
        `red_id` INT ( 10 ) UNSIGNED NOT NULL COMMENT '红包id',
        `form_content` text NOT NULL COMMENT '提交的表单内容',
        `create_time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '提交时间',
        PRIMARY KEY ( `id` ) 
    ) ENGINE = INNODB DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_hb_setting_message` (
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL,
        `await_check_tpl` VARCHAR ( 50 ) NOT NULL COMMENT '通用审核微信模板消息id',
        `result_check_tpl` VARCHAR ( 50 ) NOT NULL COMMENT '审核结果通知微信消息模板id',
        `result_check_sub` VARCHAR ( 50 ) NOT NULL COMMENT '审核结果通知微信订阅消息',
    PRIMARY KEY ( `uniacid` ) 
    ) ENGINE = INNODB DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_hb_manage` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '系统管理员',
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL COMMENT '公众号id',
        `uid` INT ( 10 ) UNSIGNED NOT NULL COMMENT '用户id',
        `email` VARCHAR ( 50 ) NOT NULL COMMENT '邮箱',
        `status` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '状态（1=正常，0=取消）',
        `create_time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '创建时间',
        `update_time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '修改时间',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = INNODB DEFAULT CHARSET = utf8;
";
pdo_run($_create_table);

/**
 * 1.1.0
 */
if(!pdo_fieldexists('kuyuan_hb_setting','low_red_money')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_hb_setting')." ADD COLUMN low_red_money double(10,2) UNSIGNED NOT NULL DEFAULT 0.00;");
}
if(!pdo_fieldexists('kuyuan_hb_red','red_form')) {
    pdo_query("ALTER TABLE ".tablename('kuyuan_hb_red')." ADD COLUMN red_form tinyint(1) UNSIGNED NOT NULL DEFAULT 0;");
}
if(!pdo_fieldexists('kuyuan_hb_red ','red_form_id')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_hb_red')." ADD COLUMN red_form_id int(10) UNSIGNED NOT NULL DEFAULT 0;");
}
